package com.share.demo;

import com.share.configuration.MyConfiguration;
import com.share.exception.ApiException;
import com.share.exception.SysException;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
 * caifan 2017/10/2
 */
@EnableTransactionManagement
//@ComponentScan
//@EnableAutoConfiguration
@Import(value = MyConfiguration.class)
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableAsync
//@ConfigurationProperties(value = "classpath:beans.xml")
@RestController
@RequestMapping("/rest/app")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @GetMapping("/error")
    public void exceptionTest(@RequestParam String msg) {
        if ("api".equals(msg)) {
            try {
                throw new ApiException("1001api");
            } catch (ApiException e) {
                throw new SysException("1001api");
            } catch (SysException e) {
                throw new SysException("1001sys");
            }
        }
        if ("sys".equals(msg)) {
            throw new SysException("1000sys");
        }
    }


}
